package com.bwie.auth.controller;

import com.bwie.auth.service.AuthService;
import com.bwie.common.domain.User;
import com.bwie.common.domain.request.UserRequest;
import com.bwie.common.domain.response.UserResponse;
import com.bwie.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Log4j2
public class AuthController {
    @Autowired
    private AuthService authService;

    @PostMapping("send/code/{phone}")
    public Result sendCode(@PathVariable("phone") String phone){
        Result result = authService.sendCode(phone);
        return result;
    }

    @PostMapping("login")
    public Result<UserResponse> login(@RequestBody UserRequest userRequest){
        Result<UserResponse> result=authService.login(userRequest);
        return result;
    }

    @GetMapping("user/info")
    public Result<User> userInfo(){
        User user = authService.userInfo();
        return Result.success(user);
    }
}
